﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Practices.Unity;
using Unity.Mvc3;
using WebStore.Domain.Entities;
using WebStore.Domain.Intializer;
using WebStore.Infrastructure.Service.Implementation;
using WebStore.Infrastructure.Service.Interface;
using WebStore.Web.App.Utility.Unity;

namespace WebStore.Web.App
{
    public static partial class Bootstrapper
    {
        static Bootstrapper()
        {
        }

        public static void Run()
        {
            var container = BuildContainer();
            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
            FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container));
            Database.SetInitializer(new EntitiesInitializer());
            CreateMapping();
        }

        private static IUnityContainer BuildContainer()
        {
            var container = new UnityContainer();
            container.RegisterType<Entities>();
            container.RegisterType<IAccountService, AccountService>();
            container.RegisterType<IOrderService, OrderService>();
            container.RegisterType<IAdminService, AdminService>();
            
            return container;
        }
    }
}